package com.ruoyi.web.controller.tool;

import com.ruoyi.quartz.domain.SysUserImport;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class TestReadFiles {
    public static void main(String[] args) throws IOException {
        List<SysUserImport> userImportList = new ArrayList<SysUserImport>();
        String filePath = "C:\\Users\\Administrator\\Desktop\\boc_portal\\o_chrm_tbl_employee_info_w.txt"; // 文本文件路径
        try (
                BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = br.readLine()) != null) {
                // 假设每行数据由逗号分隔
                String[] fields = line.split("\\s+\\|\\s+");
                if (fields.length == 9) {
                    SysUserImport userImport = new SysUserImport();
                    userImport.setDeptId(fields[0].trim());
                    userImport.setUserName(fields[1].trim());
                    userImport.setNickName(fields[2].trim());
                    userImport.setSex(fields[3].trim());
                    userImport.setStatus(fields[4].trim());
                    userImport.setCreateBy(fields[5].trim());
                    userImport.setCreateTime(dateFormat(fields[6].trim()));
                    userImport.setUpdateBy(fields[7].trim());
                    userImport.setUpdateTime(dateFormat(fields[8].trim()));
                    userImportList.add(userImport);
                }
            }
            System.out.println("SIZE:"+userImportList.size());
        }
    }
    public static Date dateFormat(String dateString){
        Date date = null;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            date = formatter.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
